package com.wei.duowan.bbs.model;

import android.os.Parcel;
import android.os.Parcelable;

import com.wei.duowan.bbs.App;
import com.wei.duowan.bbs.sql.ForumsBeanDao;

import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.query.QueryBuilder;

import java.util.List;

/**
 * 作者：赵若位
 * 时间：2019/10/28 15:35
 * 联系方式：1070138445
 * 功能：
 */
@Entity
public class ForumsBean implements Parcelable
{
    /*标题栏*/
    public static final String TYPE_GROUP = "group";
    /*菜单栏*/
    public static final String TYPE_FORUM = "forum";

    /**
     * fid : 59
     * type : group
     * name : 热门专区
     * fup : 0
     * icon : http://att.bbs.yy.com/forum/201211/06/0819488ixlxrxhzzxrk88r.png
     */

    @Id
    private String fid;
    private String type;
    private String name;
    private String fup;
    private String icon;

    @Generated(hash = 11112947)
    public ForumsBean(String fid, String type, String name, String fup, String icon)
    {
        this.fid = fid;
        this.type = type;
        this.name = name;
        this.fup = fup;
        this.icon = icon;
    }

    @Generated(hash = 826098341)
    public ForumsBean()
    {
    }

    protected ForumsBean(Parcel in)
    {
        fid = in.readString();
        type = in.readString();
        name = in.readString();
        fup = in.readString();
        icon = in.readString();
    }

    public static final Creator<ForumsBean> CREATOR = new Creator<ForumsBean>()
    {
        @Override
        public ForumsBean createFromParcel(Parcel in)
        {
            return new ForumsBean(in);
        }

        @Override
        public ForumsBean[] newArray(int size)
        {
            return new ForumsBean[size];
        }
    };

    public String getFid()
    {
        return fid;
    }

    public void setFid(String fid)
    {
        this.fid = fid;
    }

    public String getType()
    {
        return type;
    }

    public void setType(String type)
    {
        this.type = type;
    }

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public String getFup()
    {
        return fup;
    }

    public void setFup(String fup)
    {
        this.fup = fup;
    }

    public String getIcon()
    {
        return icon;
    }

    public void setIcon(String icon)
    {
        this.icon = icon;
    }

    @Override
    public int describeContents()
    {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel parcel, int i)
    {
        parcel.writeString(fid);
        parcel.writeString(type);
        parcel.writeString(name);
        parcel.writeString(fup);
        parcel.writeString(icon);
    }


    /*查询列表中的标题数据*/
    public static List<ForumsBean> getGroupForums()
    {
        QueryBuilder builder = App.getSession().getForumsBeanDao()
                .queryBuilder();
        builder.where(ForumsBeanDao.Properties.Type.eq(ForumsBean.TYPE_GROUP));
        return builder.list();
    }

    /*查询子菜单中的数据*/
    public static List<ForumsBean> getForumsBean(String fid)
    {
        QueryBuilder builder = App.getSession().getForumsBeanDao()
                .queryBuilder();
        builder.where(ForumsBeanDao.Properties.Type.eq(ForumsBean.TYPE_FORUM),ForumsBeanDao.Properties.Fup.eq(fid));
//        builder.orderDesc(ForumsBeanDao.Properties.Name);
        return builder.list();
    }
}
